package com.cupk.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
// **【核心修改】**: 使用 mybatisplus.extension.plugins.inner.PaginationInnerInterceptor
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement // 建议开启声明式事务
public class MyBatisPlusConfig {

    /**
     * 添加分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();

        // **【核心修改】**: 确认 PaginationInnerInterceptor 的导入路径
        // 这个路径对于 MP 3.4.0+ 版本是正确的
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);

        // (可选) 设置一些分页插件的属性
        // paginationInnerInterceptor.setMaxLimit(500L); // 设置单页最大数量限制，防止恶意查询

        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        return interceptor;
    }
}